package com.leyou.items.controller;

import com.leyou.items.service.GoodsItemService;
import com.leyou.items.vo.GoodsItemVo;
import lombok.experimental.Accessors;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.annotation.Resource;
import java.util.concurrent.ExecutionException;

@Controller
@RequestMapping("/item")
public class ItemsController {

    @Autowired
    GoodsItemService goodsItemService;

    /**
     * 跳转到商品详情页
     * @param model
     * @param id  spuid
     * @return
     */
    @GetMapping("/{id}.html")
    public String toItemPage(Model model, @PathVariable("id")Long id) throws ExecutionException, InterruptedException {
        GoodsItemVo goodsItemVo =  goodsItemService.items(id);
        model.addAttribute("data",goodsItemVo);
        return "item";
    }
}